<template>
    <LModalForm :visible="visible" :confirmLoading="confirmLoading" :title="title" ref="ipcMenulookForm"
        :formAttributes="formAttributes" @handleOk="handleOk" @handleCancel="handleCancel" @handlerChange="handlerChange">
    </LModalForm>
</template>

<script>
import LModalForm from "@/components/lt/form/LModalForm"
import request from '@/utils/request'
import defaultSettings from '@/config/defaultSettings'
import pick from 'lodash.pick'
export default {
    name: 'ipcMenulookForm',
    components: {
        LModalForm
    },
    data() {
        return {
            title: '详情',
            visible: false,
            confirmLoading: false,
            model: {},
            formAttributes: {
                type: '',//collapse,tabs
                formItems: [
                    {
                        title: '标签一',
                        columns: 1,
                        fields: [
                            { field: 'fileName', label: '文件名称', component: 'input', rules: [{ required: true, message: '不能为空!' }] },
                        ]
                    },
                ]

            }
        }
    },
    methods: {
        edit(record) {
            this.visible = true
            this.model["menuId"] = record.menuId
            this.model = Object.assign({}, record)
            this.$nextTick(() => {
                this.$refs.ipcMenulookForm.getForm().setFieldsValue(pick(this.model, 'fileName'))
            })
        },
        handleOk() {
            const that = this;
            this.$refs.ipcMenulookForm.getForm().validateFields((err, values) => {
                if (!err) {
                    let formData = Object.assign(this.model, values)
                    that.confirmLoading = true
                    request({ url: '/WxIpcMenuListController/save', method: 'post', data: formData }).then((res) => {
                        if (res.success) {
                            that.$message.success(res.message)
                            that.close()
                        } else {
                            that.$message.warning(res.message)
                        }
                    }).finally(() => {
                        that.confirmLoading = false

                    })

                }
            })
        },
        handleCancel() {
            this.visible = false
        },
        close() {
            this.$emit('close');
            this.visible = false;
        },
        /**
         * 表单内容发生变化
         */
        handlerChange(changeItem) {
            console.log(changeItem)

        }
    },
    created() {

    },
}
</script>